<%@page import="shoppingmall.jmu.collect.entity.Collect"%>
<%@page import="java.util.List"%>
<%@page import="shoppingmall.jmu.collect.dao.impl.CollectDAOImpl"%>
<%@page import="shoppingmall.jmu.collect.dao.CollectDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
	String user_id = request.getParameter("user_id");
	String isbn = request.getParameter("isbn");
//	System.out.print(user_id);
//	System.out.print(isbn);
	
	
	boolean flag = false;
	try{
		CollectDAO cd = new CollectDAOImpl();
		List<Collect> col = cd.getAllCollectById(user_id);
		
		if(col!=null){
			for(Collect c : col){
	//			System.out.println(c.toString());
				if(c.getProduct().equals(isbn)){
					cd.deleteCollect(user_id, isbn);
					flag = true;
					//System.out.println("已从收藏夹移除");
					break;
				}
			}
			if(!flag){
				cd.addCollect(user_id, isbn);
				//System.out.println("已添加至收藏夹");
			}
		}else{
			cd.addCollect(user_id, isbn);
			//System.out.println("已添加至收藏夹");
		}
	}catch(Exception e){
		
	}
	
	response.sendRedirect("detail.jsp?isbn="+isbn);
	
%>